const RESOLVE = 'resolved'
const REJECT = 'rejected'
const PENDING = 'pending'

class JJPromise {
    status = PENDING
    result = undefined
    reason = undefined
    constructor(execution) {
        const resolve = (result) => {
            if (this.status === PENDING) {
                this.result = result
                this.status = RESOLVE
            }
        }
        const reject = (reason) => {
            if (this.status === PENDING) {
                this.reason = reason
                this.status = REJECT
            }
        }
        execution(resolve, reject)
    }
    then(onResolved, onRejected) {
        if (this.status === RESOLVE) {
            onResolved(this.result)
        }
        if (this.status === REJECT) {
            onRejected(this.reason)
        }
    }
}



module.exports = JJPromise



const RESOLVE = 'resolved'
const REJECT = 'rejected'
const PENDING = 'pending'

class JJPromise {
    status = PENDING
    result = undefined
    reason = undefined
    constructor(execution) {
        const resolve = (result) => {
            if (this.status === PENDING) {
                this.result = result
                this.status = RESOLVE
            }
        }
        const reject = (reason) => {
            if (this.status === PENDING) {
                this.reason = reason
                this.status = RESOLVE
            }
        }
        execution(resolve, reject)
    }
    then(onResolved, onRejected) {
        if (this.status === RESOLVE) {
            onResolved(this.result)
        }
        if (this.status === REJECT) {
            onRejected(this.reason)
        }
    }
}